package com.jinyou.chengfengshop.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jinyou.chengfengshop.R;
import com.jinyou.chengfengshop.bean.CostBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by zhuzhiqiang on 2018/9/26.
 */

public class RechargeListAdapter extends RecyclerView.Adapter<RechargeListAdapter.ViewHolder> {
    private List<CostBean> rgb;
    private Context mContext;

    public RechargeListAdapter(Context mContext,List<CostBean> rgb) {
        this.mContext = mContext;
        this.rgb = rgb;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recharge_list, parent, false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        String time = formatData("yyyy-MM-dd HH:mm:ss", rgb.get(position).getCudate());
        holder.ordercount_tv.setText("订单量: " + rgb.get(position).getOrderCount());
        holder.date_tv.setText(time.substring(0,10));
        holder.psMoney_tv.setText("配送费: "+ rgb.get(position).getPsMoney());
        holder.zhichu_tv.setText("支出: " +rgb.get(position).getZhichu());
    }

    @Override
    public int getItemCount() {
        return rgb.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView date_tv;
        private TextView ordercount_tv;
        private TextView psMoney_tv;
        private TextView zhichu_tv;
        public ViewHolder(View itemView) {
            super(itemView);
            date_tv = (TextView) itemView.findViewById(R.id.date_tv);
            ordercount_tv = (TextView) itemView.findViewById(R.id.ordercount_tv);
            psMoney_tv = (TextView) itemView.findViewById(R.id.psMoney_tv);
            zhichu_tv = (TextView) itemView.findViewById(R.id.zhichu_tv);
        }
    }

    private String formatData(String dataFormat, long timeStamp) {
        if (timeStamp == 0) {
            return "";
        }

        String mm = timeStamp+"";
        mm = mm.substring(0,10);
        timeStamp = Long.parseLong(mm);

        timeStamp = timeStamp * 1000;
        String result = "";
        SimpleDateFormat format = new SimpleDateFormat(dataFormat);
        result = format.format(new Date(timeStamp));
        return result;
    }
}
